package com.yyds.oneservice.config;

import com.yyds.oneservice.interceptor.MyInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @date 2022/10/26
 * @desc
 */
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
    //配置跨域
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowCredentials(true)
                .allowedMethods("GET","POST","PUT","DELETE","HEAD","OPTIONS","TRACE","CONNECT")
                //.allowedMethods("*")
                .allowedHeaders("*")
                .allowedOriginPatterns("*")
                ;

    }
    // 配置拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 实现WebMvcConfigurer不会导致静态资源被拦截
        registry.addInterceptor(new MyInterceptor())
                .excludePathPatterns("/doc.html","/webjars/**","/swagger-resources/**")
                .addPathPatterns("/**");   // 拦截所有路径

    }
}
